package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 10 24 08 56
 **/

@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }

    /**
     * 根据id查询用户
     * ?id=123
     * @param id
     * @return
     */
    @RequestMapping("/findUserById")
    public User findUserById(@RequestParam("id") Integer id){
        log.info("传过来的userID：{}",id);
        return userService.findUserById(id);
    }

    /**
     * /getUserById/{id}:占位符 /getUserById/100
     * @PathVariable("id") Integer id
     * @param id
     * @return
     */
    @GetMapping("/getUserById/{id}")
    public User getUserById(@PathVariable("id") Integer id){
        log.info("传过来的userID：{}",id);
        return userService.findUserById(id);
    }

    @PostMapping("/insertUser")
    public int insertUser(@RequestBody User user){
        log.info("user:{}",user.toString());
        return userService.insertUser(user);
    }
}
